/**
 * @file:          Config_DriverBoard.c
 * @brief:
 * @details:
 * @author:        wjh
 * @date created:  2023.06.12
 * @version:       1.0.0
 * @par copyright (c):
 *
 * @par history (desc):
 *   version:1.0.0, wjh, 2023.06.12,12:43:05
 */
/* Include Files **************************************************************/
#include "ConfigOption.h"
#include "DefaultParam.h"
#include "main.h"
#include "string.h"

/* Function Declare ***********************************************************/

/* Global Variable Define *****************************************************/
void Config_driver_board_motor_drv42_v11(Motor_drv42 *self);
Motor_drv42 driver_board_motor_drv42_v11 = {.ConfigParam = Config_driver_board_motor_drv42_v11};
void Config_driver_board_motor_drv42_v11(Motor_drv42 *self)
{
    memset(self, 0, sizeof(Motor_drv42));
    self->ConfigParam = Config_driver_board_motor_drv42_v11;
    self->Init = Motor_drv42_v11_Init;

    /* init param */
    self->param_power_supply_V = 24;
    self->param_adc_ref_V = 3.3;
    self->param_amp_gain = 20;
    self->param_power_voltage_sample_gain = 11.234F / 1.0F;
    self->param_R_of_current_sample_ohm = 0.015;
    self->param_adc_calibration_start_index = 100;
    self->param_adc_calibration_buffer_size = 3000;
    self->param_led_toggle_period_s = 0.5;
    self->param_current_dir = -1;
    self->param_pwm_output_en = FALSE;
    self->param_mos_Ron = 0.200;
    self->param_mos_deadtime = 250e-9;
    self->param_mos_rise_fall_time = 150e-9;
    self->param_mos_max_peak_current = 6.0;
    self->param_mos_max_continuous_current = 4.0;

    /* ch32v303 pin set */
    // self->param_pin_LED.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // // self->param_pin_OSCIN.mode = GPIO_GENERAL_MODE_NULL;
    // // self->param_pin_OSCOUT.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_CAL_EN.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_OP2_B_OUT.mode = GPIO_GENERAL_MODE_ANALOG_IN;
    // self->param_pin_OP1_A_OUT.mode = GPIO_GENERAL_MODE_ANALOG_IN;
    // self->param_pin_MT_GSENSOR_CS.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_SPI_CLK.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_SPI_MISO.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_SPI_MOSI.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_UART_TX.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_UART_RX.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_OP2_N_IN.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_OP1_N_IN.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // // self->param_pin_OP2_P_IN.mode = GPIO_GENERAL_MODE_NULL;
    // // self->param_pin_OP1_P_IN.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_PWM_IN_A1.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_A2.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_B1.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_B2.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // // self->param_pin_SWC.mode = GPIO_GENERAL_MODE_NULL;
    // // self->param_pin_SWD.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_STEP.mode = GPIO_GENERAL_MODE_IN_PULL_DOWN;
    // self->param_pin_DIR.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_EN.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_EMERGENCY.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_TestGpio.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
}

void Config_driver_board_motor_drv42_v12(Motor_drv42 *self);
Motor_drv42 driver_board_motor_drv42_v12 = {.ConfigParam = Config_driver_board_motor_drv42_v12};
void Config_driver_board_motor_drv42_v12(Motor_drv42 *self)
{
    memset(self, 0, sizeof(Motor_drv42));
    self->ConfigParam = Config_driver_board_motor_drv42_v12;
    self->Init = Motor_drv42_v12_Init;

    /* init param */
    self->param_power_supply_V = 24;
    self->param_adc_ref_V = 3.3;
    self->param_amp_gain = 20;
    self->param_power_voltage_sample_gain = 11.234F / 1.0F;
    self->param_R_of_current_sample_ohm = 0.015;
    self->param_adc_calibration_start_index = 100;
    self->param_adc_calibration_buffer_size = 3000;
    self->param_led_toggle_period_s = 0.5;
    self->param_current_dir = -1;
    self->param_pwm_output_en = FALSE;
    self->param_mos_Ron = 0.200;
    self->param_mos_deadtime = 250e-9;
    self->param_mos_rise_fall_time = 150e-9;
    self->param_mos_max_peak_current = 6.0;
    self->param_mos_max_continuous_current = 4.0;

    /* ch32v303 pin set */
    // self->param_pin_LED.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_OSCIN.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_OSCOUT.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_CAL_EN.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_OP2_B_OUT.mode = GPIO_GENERAL_MODE_ANALOG_IN;
    // self->param_pin_OP1_A_OUT.mode = GPIO_GENERAL_MODE_ANALOG_IN;
    // self->param_pin_MT_GSENSOR_CS.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_SPI_CLK.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_SPI_MISO.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_SPI_MOSI.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_STEP_B1.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_STEP_B0.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_PWM_IN_A1.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_A2.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_B1.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_B2.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_STEP_A1.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_SWD.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_SWC.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_STEP_A0.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_EMERGENCY.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_STEP.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_EN.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_UART_TX.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_UART_RX.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_DIR.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_TestGpio.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_Vin.mode = GPIO_GENERAL_MODE_ANALOG_IN;
}

void Config_driver_board_motor_drv36_v22(Motor_drv42 *self);
Motor_drv42 driver_board_motor_drv36_v22 = {.ConfigParam = Config_driver_board_motor_drv36_v22};
void Config_driver_board_motor_drv36_v22(Motor_drv42 *self)
{
    memset(self, 0, sizeof(Motor_drv42));
    self->ConfigParam = Config_driver_board_motor_drv36_v22;
    self->Init = Motor_drv42_v11_Init;

    /* init param */
    self->param_power_supply_V = 24;
    self->param_adc_ref_V = 3.3;
    self->param_amp_gain = 20;
    self->param_power_voltage_sample_gain = 11.234F / 1.0F;
    self->param_R_of_current_sample_ohm = 0.020;
    self->param_adc_calibration_start_index = 100;
    self->param_adc_calibration_buffer_size = 3000;
    self->param_led_toggle_period_s = 0.5;
    self->param_current_dir = -1;
    self->param_pwm_output_en = FALSE;
    self->param_mos_Ron = 0.200;
    self->param_mos_deadtime = 250e-9;
    self->param_mos_rise_fall_time = 150e-9;
    self->param_mos_max_peak_current = 6.0;
    self->param_mos_max_continuous_current = 4.0;

    /* ch32v303 pin set */
    // self->param_pin_LED.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // // self->param_pin_OSCIN.mode = GPIO_GENERAL_MODE_NULL;
    // // self->param_pin_OSCOUT.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_CAL_EN.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_OP2_B_OUT.mode = GPIO_GENERAL_MODE_ANALOG_IN;
    // self->param_pin_OP1_A_OUT.mode = GPIO_GENERAL_MODE_ANALOG_IN;
    // self->param_pin_MT_GSENSOR_CS.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_SPI_CLK.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_SPI_MISO.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_SPI_MOSI.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_UART_TX.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_UART_RX.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_OP2_N_IN.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_OP1_N_IN.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // // self->param_pin_OP2_P_IN.mode = GPIO_GENERAL_MODE_NULL;
    // // self->param_pin_OP1_P_IN.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_PWM_IN_A1.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_A2.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_B1.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_B2.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // // self->param_pin_SWC.mode = GPIO_GENERAL_MODE_NULL;
    // // self->param_pin_SWD.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_STEP.mode = GPIO_GENERAL_MODE_IN_PULL_DOWN;
    // self->param_pin_DIR.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_EN.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_EMERGENCY.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_TestGpio.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
}

void Config_driver_board_motor_drv42_v23(Motor_drv42 *self);
Motor_drv42 driver_board_motor_drv42_v23 = {.ConfigParam = Config_driver_board_motor_drv42_v23};
void Config_driver_board_motor_drv42_v23(Motor_drv42 *self)
{
    memset(self, 0, sizeof(Motor_drv42));
    self->ConfigParam = Config_driver_board_motor_drv42_v23;
    self->Init = Motor_drv42_v12_Init;

    /* init param */
    self->param_power_supply_V = 24;
    self->param_adc_ref_V = 3.3;
    self->param_amp_gain = 20;
    self->param_power_voltage_sample_gain = 11.234F / 1.0F;
    self->param_R_of_current_sample_ohm = 0.050;
    self->param_adc_calibration_start_index = 100;
    self->param_adc_calibration_buffer_size = 3000;
    self->param_led_toggle_period_s = 0.5;
    self->param_current_dir = -1;
    self->param_pwm_output_en = FALSE;
    self->param_mos_Ron = 0.200;
    self->param_mos_deadtime = 250e-9;
    self->param_mos_rise_fall_time = 150e-9;
    self->param_mos_max_peak_current = 6.0;
    self->param_mos_max_continuous_current = 4.0;

    /* ch32v303 pin set */
    self->param_pin_STEP.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    self->param_pin_DIR.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    self->param_pin_EN.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    self->param_pin_STALL_OUT.mode = GPIO_GENERAL_MODE_NULL;
    self->param_pin_BUZZER_EN.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    self->param_pin_MOTER_PWR_EN.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    self->param_pin_UART1_TX.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    self->param_pin_UART1_RX.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    self->param_pin_ADC_VOUT.mode = GPIO_GENERAL_MODE_ANALOG_IN; // GPIO_GENERAL_MODE_NULL; //GPIO_GENERAL_MODE_ANALOG_IN
    self->param_pin_ADC_VIN.mode = GPIO_GENERAL_MODE_NULL;
    self->param_pin_KEY1.mode = GPIO_GENERAL_MODE_NULL;
    self->param_pin_KEY2.mode = GPIO_GENERAL_MODE_NULL;
    self->param_pin_START.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    self->param_pin_STOP.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    self->param_pin_UART_TX.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    self->param_pin_UART_RX.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    self->param_pin_LED_GREEN.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    self->param_pin_LED_RED.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    self->param_pin_LED_STATUS1.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    self->param_pin_LED_STATUS2.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;



    // self->param_pin_LED.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_OSCIN.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_OSCOUT.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_CAL_EN.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_OP2_B_OUT.mode = GPIO_GENERAL_MODE_ANALOG_IN;
    // self->param_pin_OP1_A_OUT.mode = GPIO_GENERAL_MODE_ANALOG_IN;
    // self->param_pin_MT_GSENSOR_CS.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_SPI_CLK.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_SPI_MISO.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_SPI_MOSI.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_STEP_B1.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_STEP_B0.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_PWM_IN_A1.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_A2.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_B1.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_PWM_IN_B2.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_STEP_A1.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_SWD.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_SWC.mode = GPIO_GENERAL_MODE_NULL;
    // self->param_pin_STEP_A0.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_EMERGENCY.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_STEP.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_EN.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_UART_TX.mode = GPIO_GENERAL_MODE_AF_PUSH_PULL;
    // self->param_pin_UART_RX.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_DIR.mode = GPIO_GENERAL_MODE_IN_PULL_UP;
    // self->param_pin_TestGpio.mode = GPIO_GENERAL_MODE_OUT_PUSH_PULL;
    // self->param_pin_Vin.mode = GPIO_GENERAL_MODE_ANALOG_IN;
}